package enum_demo.sys_enum_demo;

/**
 * @author ChenYongHao
 * @date 2023/5/4 11:46
 * @desc 常见方法
 */
public class EnumMethodDemo {
    public static void main(String[] args) {
        // int compareTo(E o)
        Direction2 d21 = Direction2.FRONT;
        Direction2 d22 = Direction2.BEHIND;
        Direction2 d23 = Direction2.LEFT;
        Direction2 d24 = Direction2.RIGHT;
        System.out.println(d21.compareTo(d24));
        System.out.println(d22.compareTo(d23));
        System.out.println(d23.compareTo(d22));
        System.out.println(d24.compareTo(d21));
        System.out.println("---------------");
        // String name()
        System.out.println(d21.name());
        System.out.println(d22.name());
        System.out.println(d23.name());
        System.out.println(d24.name());
        System.out.println("--------------");
        // int ordinal()
        System.out.println(d21.ordinal());
        System.out.println(d22.ordinal());
        System.out.println(d23.ordinal());
        System.out.println(d24.ordinal());
        System.out.println("--------------");
        // String toString()
        System.out.println(d21.toString());
        System.out.println(d22.toString());
        System.out.println(d23.toString());
        System.out.println(d24.toString());
        System.out.println("--------------");
        // <T> T valueOf(Class<T> type,String name)
        Direction2 d = Enum.valueOf(Direction2.class, "FRONT");
        System.out.println(d.getName());
        System.out.println("----------------");
        // values()
        Direction2[] directions = Direction2.values();
        for (Direction2 direction : directions) {
            System.out.println(direction + ":" + direction.getName());
        }
    }
}

